home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DApp / SeqPup.cpp < prev    next >
C/C++ Source or Header  |  1996-07-05  |  21KB  |  818 lines

  1. // SeqPup.cp
  2. // d.g.gilbert -- biosequence editor & analysis platform
  3. // Jan 1994
  4.  
  5. #define UseGopher  0
  6. #undef  DEBUG
  7. #define SEQASM
  8.  
  9. #include <DClap.h>
  10. #if UseGopher
  11. #  include <DNet.h>
  12. #else
  13. #  include <DTCP.h>
  14. #  include <DSMTPclient.h>
  15. #  include <DSendMailDialog.h>
  16. #endif
  17. #include <DBio.h>
  18. #include <DRich.h>
  19. #include <DDrawPICT.h>
  20. #include <DSeqPict.h>
  21. #include <Dversion.h>
  22. #include <DBOPclient.h>
  23.  
  24. #ifdef SEQASM
  25. #include <DSeqAsmDoc.h>
  26. #endif
  27.  
  28. #if DEBUG
  29. #include <DebugNew.h>
  30. #endif
  31.  
  32. void AboutSeqPupPicture(); // DAboutSeqPup.cpp
  33.  
  34.  
  35.  
  36. class DSeqPup : public DApplication
  37. {
  38. public:
  39.     static char* kBugmailAddress;
  40.     static char* kGopherRTFDocSuffix;
  41.     
  42.     enum appMenus { kInternetMenu = 100, kPrefsMenu, kOpenMenu };  
  43.     enum menuCmds { 
  44.         kSeqPrefs=1001,  kOtherPrefs, kEditGopherMap,
  45.         kViewByDefault,kViewByDate,kViewBySize,kViewByName,kViewByKind,kViewByHost,
  46.         kViewAsText, kViewAsLink,
  47.         kOpenDoc, kFetchLink, kFetchDefault, // kFetchView1...kFetchViewN
  48.         kFetchOptionFlag, kAutoloadFlag,
  49.         kViewPrefs, kCodonPref,kREnzymePref,kColorPref,kStylePref,
  50.         kSaveWinPrefs,kSeqPrintPrefs, kSeqDocPrefs, kBOPprefs,
  51.         kGetInfo, kMailAdmin, kOpenLocalGo,
  52.         kNewServer,kFindServer,kNewLink, kEditLink,kExtractGodoc,kLockWindow,
  53.         kOpenText, kOpenSeq, kOpenAppendSeq, kOpenTree,  
  54.         kMailSetup, kSendMail, kBugMail
  55.         };
  56.  
  57.     DView *    fFetchOptionMenuItem;
  58.     DView *    fLockWinMenuItem;
  59.     DView * fAutoloadItem;
  60.     DMenu * fViewsMenu;
  61.     Boolean fWinPrefsNotSaved, fAppendSeq;
  62.     
  63.     void ISeqPup();     
  64.     virtual ~DSeqPup();
  65.     void DoAboutBox();
  66.  
  67.     virtual void SetUpMenus();    
  68.     virtual Boolean DoMenuTask(long tasknum, DTask* theTask);
  69.     virtual    Boolean IsMyAction(DTaskMaster* action);
  70.     virtual Boolean IsInternetMenu(DTaskMaster* action); 
  71.     virtual    void UpdateMenus(); 
  72.     virtual void OpenDocument(DFile* aFile);
  73.     virtual void OpenLocalGopher();
  74.     DWindow* DoMakeDocument(short itsCommandNumber, DFile* aFile);
  75. };
  76.  
  77.  
  78. char* DSeqPup::kBugmailAddress= "seqpup@bio.indiana.edu";
  79. char* DSeqPup::kGopherRTFDocSuffix = ".start";
  80.  
  81.  
  82.     // here we go -- the Nlm_Main() program (called from main() in ncbimain.c)
  83. extern "C" short Main(void)
  84. {
  85.   DSeqPup* app = new DSeqPup();
  86.   app->ISeqPup();
  87.   app->Run();
  88.   delete app; 
  89.   return 0;
  90. }
  91.  
  92.  
  93.  
  94. void DSeqPup::ISeqPup()
  95. {
  96.     DApplication::kName= "SeqPup";
  97.     DApplication::kVersion= (char*) kDCLAPVersionString; //" v 0.4";
  98.     
  99.     fFetchOptionMenuItem= NULL;
  100.     fLockWinMenuItem= NULL;
  101.     fWinPrefsNotSaved= true;
  102.     fAppendSeq= false;
  103.     fAutoloadItem = NULL;
  104. #if UseGopher
  105.     gGopherDoc = NULL; // ??? this should be set, but isn't in 68K ??
  106. #endif
  107.     fViewsMenu= NULL;
  108.     fFileSuffix = NULL; // unix, msdos file suffix
  109.     fAcceptableFileTypes = NULL;     // really want "IGo4 BKMK TEXT" and perhaps others
  110.                                                                 // but NCBI tools only handle 1 type now
  111.     IApplication();
  112.     
  113. #if UseGopher
  114.         // network doc initializations
  115.     InitializeUGopher();
  116.     DGoviewPrefs::InitGlobals();
  117.     DGoOtherPrefs::InitGlobals();
  118.     if (fFetchOptionMenuItem) fFetchOptionMenuItem->SetStatus(DGopherListDoc::gOptionIsOn);
  119.     if (fAutoloadItem) fAutoloadItem->SetStatus(DGoLinkedTextDoc::gAutoloadInlines);
  120. #endif
  121.  
  122.     DRichView::InitRichView();
  123.     
  124.         // sequence initializations
  125.     DSeqDoc::GetGlobals(); //SeqDocPrefs(kSeqDocPrefInit);
  126.     DCodons::Initialize("codon","data","tables:codon.table");
  127.     DREMap::Initialize("renzyme","data","tables:renzyme.table");
  128.     DBaseColors::Initialize("color","data","tables:color.table");
  129.     if (DBaseColors::NotAvailable()) ; // read in DBaseColors data now 
  130.     DStyleTable::Initialize("seqmasks","data","tables:seqmasks.table");
  131.     if (DStyleTable::NotAvailable()) ; // read in DStyleTable data now 
  132.     
  133.         // default documents ??
  134.   if (! OpenStartDocs() )
  135.     if (DSeqDoc::fgStartDoc) DSeqDoc::NewSeqDoc();
  136.     
  137.     {
  138.         // open default gopher document if it exists.
  139.         // TRY RTF Form first (.start ?? )
  140.         // open both default.go4 and default.start files, if they exist !
  141.     char godefault[512];
  142. #if UseGopher
  143.     StrNCpy(godefault, (char*)Shortname(), 512);    
  144.     StrNCat(godefault, DGopherListDoc::kGopherDocSuffix, 512);
  145.     DApplication::OpenDocument( (char*)godefault);
  146. #endif
  147.     StrNCpy(godefault, (char*)Shortname(), 512);    
  148.     StrNCat(godefault, kGopherRTFDocSuffix, 512);
  149.     DApplication::OpenDocument( (char*)godefault);
  150.     }
  151.  
  152. }     
  153.  
  154.  
  155. DSeqPup::~DSeqPup()
  156. {
  157. #if UseGopher
  158.     DGoviewPrefs::SaveGlobals();
  159.     DGoOtherPrefs::SaveGlobals();
  160. #endif
  161.     if (fWinPrefsNotSaved) DSeqDoc::SaveGlobals(); 
  162.     DDrawPict::Cleanup();
  163. }
  164.  
  165.  
  166. void DSeqPup::DoAboutBox()
  167. {
  168. #if !defined(WIN_MSWIN) && !defined(WIN_MOTIF)
  169.         // problems yet w/ this large codepic in mswin(WIN16) and unix/motif
  170.     AboutSeqPupPicture();
  171. #else
  172.     char aboutMe[512];
  173.     sprintf( aboutMe, "SeqPup, version %s"LINEEND
  174.                 " a biosequence editor & analysis application "LINEEND
  175.                 " copyright by D.G. Gilbert, 1990-1995"
  176.                 , DApplication::kVersion);
  177.     DAboutBoxWindow* about = new DAboutBoxWindow(aboutMe);
  178. #endif
  179. }
  180.  
  181.  
  182. void DSeqPup::SetUpMenus(void)
  183. {
  184.     //DApplication::SetUpMenus();
  185.  
  186.     DMenu* aMenu = NULL;
  187. #ifdef WIN_MAC
  188.     DAppleMenu* appleMenu = new DAppleMenu(this,fAboutLine);
  189. #endif
  190.     if (!aMenu) aMenu = this->NewMenu( cFileMenu, "File");
  191. #ifndef WIN_MAC
  192.     aMenu->AddItem(kAbout, fAboutLine);
  193.     aMenu->AddSeparator();
  194. #endif
  195.     aMenu->AddItem(kNew,"New/N", false, true);
  196.  
  197.     aMenu->AddItem( kOpenSeq, "Open sequence.../O",false, true);
  198.     //aMenu->AddItem(kOpen,"Open.../O",false, true);
  199.     DMenu* oMenu= new DSubMenu( kOpenMenu, aMenu, "Open other");
  200.     //oMenu->AddItem( kOpenSeq, "Sequence file.../O",false, true);
  201.     oMenu->AddItem( kOpenText, "Text,RTF,Image...",false, true);
  202.     oMenu->AddItem( kOpenAppendSeq, "Append sequence...",false, true);
  203.     //oMenu->AddItem( kOpenTree, "Phylogenetic tree...",false, true);
  204.     //oMenu->AddItem( kOpenLocalGo,"Open Local gopher...",false, true);
  205.     //oMenu->AddItem( kNewServer,"Open Remote.../R",false, true);
  206.  
  207.     aMenu->AddSeparator();
  208.     aMenu->AddItem(kClose,"Close/W",false, true);
  209.     aMenu->AddItem(kSave,"Save/S",false, true);
  210.     aMenu->AddItem(kSaveAs,"Save As...",false, true);
  211.     aMenu->AddItem(DSeqDoc::cSaveSel,"Save selection...",false, true);
  212.     aMenu->AddItem(DSeqDoc::cRevert,"Revert to saved",false, true);
  213.     aMenu->AddSeparator();
  214.     aMenu->AddItem(kPrint,"Print",false, true);
  215.     aMenu->AddItem(kHelp,"Help/H",false, true);
  216.     aMenu->AddSeparator();
  217.     aMenu->AddItem(kQuit,"Quit/Q",false, true);
  218.  
  219.     aMenu= NULL;
  220.     this->SetUpMenu(DApplication::cEditMenu, aMenu);
  221.     DSeqDoc::SetUpMenu(DApplication::cEditMenu, aMenu);
  222.  
  223.     DMenu* sMenu = NULL;
  224.     DSeqDoc::SetUpMenu(DSeqDoc::kSeqMenu, sMenu);
  225.  
  226.     DMenu* iMenu = NewMenu( kInternetMenu, "Internet");
  227.     //iMenu->AddItem( kMailSetup, "Mail setup...");
  228.      //iMenu->AddSeparator();        
  229.  
  230.     DSeqDoc::SetUpMenu(DSeqDoc::kInternetMenu, iMenu);
  231.      iMenu->AddSeparator();        
  232.     DSeqApps::SetUpMenu(DSeqDoc::kInternetMenu, iMenu, "inet");
  233.      iMenu->AddSeparator();        
  234.     iMenu->AddItem( kSendMail, "Send Mail...");
  235.     iMenu->AddItem( kBugMail, "Comment on this app...");
  236.  
  237.     DMenu* cMenu = NULL;
  238.     DSeqApps::SetUpMenu(DSeqApps::kChildMenu, cMenu, DSeqApps::kAppSection);
  239.     
  240.     iMenu = NewMenu( kPrefsMenu, "Options");
  241.     iMenu->AddItem( kSeqDocPrefs, "Seq Prefs...",false, true);
  242.     iMenu->AddItem( kSeqPrintPrefs, "SeqPrint Prefs...", false, true); 
  243.     iMenu->AddItem( kColorPref, "Base color table...", false, true);
  244.     iMenu->AddItem( kStylePref, "Base style table...", false, true);
  245.     iMenu->AddItem( kCodonPref, "Codon table...", false, true);
  246.     iMenu->AddItem( kREnzymePref, "R.Enzyme table...", false, true);
  247.     iMenu->AddItem( kSaveWinPrefs, "Save window settings", false, true);
  248.     // add opt to save current aln window size,text-lock,color-state to prefs ?
  249.     // or do automatically on close?
  250.     iMenu->AddSeparator();
  251.     
  252. #if UseGopher
  253.     iMenu->AddItem( kViewPrefs, "View Prefs...", false, true); 
  254. #if NETSTUF_LATER
  255.     iMenu->AddItem( kFetchOptionFlag, "Fetch with options", true, true);
  256.         // we can only access menu item thru gViewCentral now the way DMenu::AddItem() is written...
  257.     fFetchOptionMenuItem= (DView*) gViewCentral->GetView(kFetchOptionFlag);
  258.  
  259.     iMenu->AddItem( kAutoloadFlag, "Autoload images", true, true);
  260.     fAutoloadItem= (DView*) gViewCentral->GetView(kAutoloadFlag);
  261.     iMenu->AddItem( kEditGopherMap, "Edit view handlers...",false, true);
  262.     iMenu->AddItem( kOtherPrefs,     "Other prefs...",false, true);
  263. #endif
  264. #endif
  265.     iMenu->AddItem( kBOPprefs,  "BOP setup...", false, true);
  266.     iMenu->AddItem( kMailSetup, "Mail setup...",false, true);
  267.  
  268.     aMenu= NULL;
  269.     this->SetUpMenu(DApplication::cWindowMenu, aMenu);
  270.     
  271.     this->SetUpMenu( 0, aMenu);
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278. class    DBugMailDialog : public DSendMailDialog
  279. {
  280. public:
  281.     DBugMailDialog(long id, DTaskMaster* itsSuperior,
  282.         short width = -5, short height = -5, short left = -50, short top = -20, char* title = NULL):
  283.         DSendMailDialog(id, itsSuperior, width, height, left, top, title)
  284.         {}
  285.  
  286.     virtual DView* InstallTo(DView* super, char* toStr)  //override
  287.     {
  288.         return DSendMailDialog::InstallTo(super, DSeqPup::kBugmailAddress);
  289.     }
  290. };
  291.  
  292.  
  293.  
  294. #if UseGopher
  295. class DLocalDialog : public DWindow
  296. {
  297. public:
  298.     enum { kSetDefault = 13345 };
  299.     DEditText* fQuery;
  300.     DLocalDialog();            
  301.     char* Result();
  302.     void OkayAction();
  303. };
  304.  
  305.  
  306. DLocalDialog::DLocalDialog() :
  307.     DWindow( 0, gApplication, fixed, -10, -10, -50, -20, "Local Gopher", kDontFreeOnClose)
  308. {
  309.         new DPrompt(0, this, "Open local folder?", 0, 0, Nlm_systemFont);             
  310.         this->NextSubviewBelowLeft();
  311.         fQuery= new DEditText(0, this, gLocalGopherRoot, 28); 
  312.         this->SetEditText(fQuery);
  313.         this->NextSubviewBelowLeft();
  314.         (void) new DCheckBox(kSetDefault,this,"Make this default local services folder");
  315.         this->AddOkayCancelButtons();
  316. }
  317.             
  318. void DLocalDialog::OkayAction() 
  319.     DWindow::OkayAction();
  320.     DCheckBox* ck = (DCheckBox*) this->FindSubview(kSetDefault);
  321.     if (ck && ck->GetStatus()) {
  322.         char* newroot= fQuery->GetText(); // this dups text
  323.         if (newroot) {
  324.             MemFree(gLocalGopherRoot);
  325.             gLocalGopherRoot= newroot;
  326.             }
  327.         }
  328. }
  329.  
  330. char* DLocalDialog::Result()
  331. {
  332.     if (fOkay) return fQuery->GetText();
  333.     else return NULL;
  334. }
  335. #endif
  336.  
  337.  
  338. void DSeqPup::OpenLocalGopher()
  339. {
  340. #if UseGopher
  341.     DLocalDialog* win= new DLocalDialog();
  342.     if ( win->PoseModally() ) {
  343.         char* localpath= win->Result();
  344.       DGopher* localgo= DGopherList::LocalGopher( localpath);
  345.         MemFree( localpath);
  346.       DGopherListDoc::ProcessGopher( localgo, 0);
  347.       }
  348.     delete win;  
  349. #endif
  350. }
  351.         
  352.  
  353. // DEBUG TEST of DChildDlogDoc
  354. #include "DChildDlogDoc.h"
  355.  
  356. void DSeqPup::OpenDocument(DFile* aFile)
  357. {
  358.     if (!aFile || !aFile->Exists()) return;
  359.     gCursor->watch();
  360.  
  361. #ifdef SEQASM    
  362.     if (DSeqAsmDoc::IsAutoseqFile(aFile)) {
  363.         
  364.         fAppendSeq= true; // !? expect ~6 data files from autoseq analysis
  365.                                             // all belong to same window...
  366.                                             // can we load these at same time somehow ??
  367.                                             // e.g., same file name, diff. suffix?
  368.         if (fAppendSeq) {
  369.             DSeqAsmDoc* sdoc= (DSeqAsmDoc*) gWindowManager->CurrentWindow();
  370.             if (sdoc && sdoc->Id() == DSeqAsmDoc::kSeqAsmdoc) 
  371.                 sdoc->Open(aFile);   
  372.             else
  373.                 fAppendSeq= false;
  374.             }
  375.         if (!fAppendSeq) {
  376.             DSeqAsmDoc* sdoc= new DSeqAsmDoc(DSeqAsmDoc::kSeqAsmdoc, NULL, NULL);
  377.             sdoc->Open(aFile);   
  378.             }
  379.         }
  380.     else 
  381. #endif
  382.  
  383.     if (DSeqDoc::IsSeqFile(aFile)) {
  384.         if (fAppendSeq) {
  385.             DSeqDoc* sdoc= (DSeqDoc*) gWindowManager->CurrentWindow();
  386.             if (sdoc && sdoc->Id() == DSeqDoc::kSeqdoc) 
  387.                 sdoc->Open(aFile);   
  388.             else
  389.                 fAppendSeq= false;
  390.             }
  391.         if (!fAppendSeq) {
  392.             DSeqDoc* sdoc= new DSeqDoc(DSeqDoc::kSeqdoc, NULL, NULL);
  393.             sdoc->Open(aFile);   
  394.             }
  395.         }
  396.         
  397.     else {
  398.         aFile->Close();
  399. #if UseGopher
  400.       DGopher* localgo= DGopherList::LocalGopher( aFile);
  401.       DGopherListDoc::ProcessGopher( localgo, 0);
  402. #else
  403.                 // DEBUG TEST of DChildDlogDoc ...
  404.         //DChildDlogDoc* doc= new DChildDlogDoc( 0, gTextFont);
  405.         DRichTextDoc* doc= new DRichTextDoc( 0, true, gTextFont);
  406.         doc->Open( aFile);
  407. #endif
  408.         }
  409.     gCursor->arrow();
  410. }
  411.  
  412.  
  413.  
  414. DWindow* DSeqPup::DoMakeDocument(short itsCommandNumber, DFile* aFile)
  415. {
  416.     DWindow* theDoc= NULL;
  417.     
  418.      switch (itsCommandNumber) {
  419. #if 0
  420.         case cOpenNAColors:
  421.         case cOpenAAColors: {
  422.             DColorPrefDocument* aDoc= new DColorPrefDocument();
  423.             if (itsCommandNumber == cOpenAAColors)
  424.                 aDoc->IColorPrefDocument( itsFile, kAmino);
  425.             else 
  426.                 aDoc->IColorPrefDocument( itsFile, kDNA);
  427.             return aDoc;
  428.             }
  429.  
  430.         case cOpenTree: {
  431.             DTreeDoc* aDoc= new DTreeDoc();
  432.             aDoc->ITreePrintDocument(kPrintClipType, NULL, NIL, itsFile);
  433.             return aDoc;
  434.             }
  435.         
  436.         // also handle gopher documents ... some gopher method should do this
  437.         
  438.         default:  { //== cNewProj/cOpenProj, cNew/cOpen
  439.             DAlnDoc* aDoc= new DAlnDoc();
  440.             aDoc->IAlnDoc( itsFile);
  441.             return aDoc;
  442.             }
  443. #endif
  444.         }
  445.         
  446.     return theDoc;
  447. }
  448.  
  449.  
  450.  
  451.  
  452.  
  453.         
  454. Boolean DSeqPup::IsInternetMenu(DTaskMaster* action) 
  455. {
  456.     DWindow* win;
  457.     DSeqDoc* sdoc = (DSeqDoc*) gWindowManager->CurrentWindow();
  458.  
  459.     switch(action->Id()) {
  460.  
  461.         case kCodonPref: 
  462.             DCodons::TableChoice();
  463.             return true;
  464.  
  465.         case kColorPref: 
  466.             DBaseColors::TableChoice();
  467.             return true;
  468.  
  469.         case kStylePref: 
  470.             DStyleTable::TableChoice();
  471.             return true;
  472.             
  473.         case kREnzymePref: 
  474.             DREMap::TableChoice();
  475.             return true;
  476.             
  477.         case kSaveWinPrefs: 
  478.             if (sdoc && sdoc->Id() == DSeqDoc::kSeqdoc) {
  479.                 sdoc->MakeGlobalsCurrent();
  480.                 DSeqDoc::SaveGlobals();
  481.                 fWinPrefsNotSaved= false;
  482.                 }
  483.             return true;
  484.  
  485.         case kBOPprefs: 
  486.             BOPSetLogon();
  487.             return true;
  488.  
  489.         case kSeqDocPrefs: 
  490.             SeqDocPrefs(kSeqDocPrefDialog);
  491.             return true;
  492.     
  493.         case kSeqPrintPrefs: 
  494.             SeqPrintPrefs(kSeqPrintPrefDialog);
  495.             return true;
  496.  
  497. #if UseGopher
  498.         case kViewPrefs: 
  499.             if (!gGoviewPrefs) {
  500.                 gGoviewPrefs = new DGoviewPrefs();
  501.                 gGoviewPrefs->Initialize();
  502.                 }
  503.             if (gGoviewPrefs && gGoviewPrefs->PoseModally()) ;
  504.             //delete gGoviewPrefs; // leave the window hidden but alive for later use
  505.             return true;
  506.             
  507.         case kOtherPrefs:
  508.             if (!gGoOtherPrefs) {
  509.                 gGoOtherPrefs = new DGoOtherPrefs();
  510.                 gGoOtherPrefs->Initialize();
  511.                 }
  512.             if (gGoOtherPrefs && gGoOtherPrefs->PoseModally()) ;
  513.             //delete gGoOtherPrefs; // leave the window hidden but alive for later use
  514.             return true;
  515.  
  516.         case  kFetchOptionFlag:
  517.             if (fFetchOptionMenuItem) DGopherListDoc::gOptionIsOn= fFetchOptionMenuItem->GetStatus();
  518.             else DGopherListDoc::gOptionIsOn = !DGopherListDoc::gOptionIsOn; // or read menu state
  519.             return true;
  520.  
  521.         case  kAutoloadFlag:
  522.             if (fAutoloadItem) DGoLinkedTextDoc::gAutoloadInlines= fAutoloadItem->GetStatus();
  523.             else DGoLinkedTextDoc::gAutoloadInlines = !DGoLinkedTextDoc::gAutoloadInlines; // or read menu state
  524.             return true;
  525.  
  526.         case  kExtractGodoc:
  527.             {
  528.             win= gWindowManager->CurrentWindow();
  529.             if (win && win->Id() == DGoLinkedTextDoc::kGoLitextdoc) {
  530.                 DGoLinkedTextDoc* ndoc= (DGoLinkedTextDoc *) win;
  531.                 switch (action->Id()) {
  532.                     case kExtractGodoc    : ndoc->ExtractGopherDoc(); break;
  533.                     }
  534.                 }
  535.             return true;
  536.             }
  537.  
  538.  
  539.         case  kLockWindow:
  540.             win= gWindowManager->CurrentWindow();
  541.             if (win && fLockWinMenuItem) {
  542.                 if (win->Id() == DGopherListDoc::kGoListdoc)
  543.                      ((DGopherListDoc *) win)->PinWindow( fLockWinMenuItem->GetStatus());
  544.                 else if (win->Id() == DGopherTextDoc::kGoTextdoc   
  545.                             || win->Id() == DGoLinkedTextDoc::kGoLitextdoc)  
  546.                     ((DGopherTextDoc *) win)->PinWindow( fLockWinMenuItem->GetStatus());
  547.                 }         
  548.             return true;
  549. #endif
  550.  
  551. #if UseGopher
  552.         case     kGetInfo:
  553.         case  kFetchLink:
  554.         case  kMailAdmin:
  555.         case    kFindServer:
  556.         case    kNewServer:
  557.         case    kNewLink:
  558.         case  kEditLink:
  559.             {
  560.             win= gWindowManager->CurrentWindow();
  561.             if (win && win->Id() == DGopherListDoc::kGoListdoc) {
  562.                 DGopher* go;
  563.                 short iview;
  564.                 DGopherListDoc* gdoc= (DGopherListDoc *) win;
  565.                 switch (action->Id()) {
  566.  
  567.                     case kFindServer:    gdoc->TopOfGopherHole(); break;
  568.                     case kNewServer    : gdoc->InsertNewGopher( false); break;
  569.                     case kNewLink        : gdoc->InsertNewGopher( true); break;
  570.                     case kEditLink    : gdoc->EditOldGopher(); break;
  571.                     case kGetInfo:
  572.                         iview= DGopher::kGetItemInfo;
  573.                             // fall thru to kFetchLink
  574.                     case kFetchLink:
  575.                         go= gdoc->fGoview->SelectedGopher();
  576.                         if (go) gdoc->ProcessGopher(go, iview);
  577.                         break;
  578. #if 0                    
  579.                     case kMailAdmin    :
  580.                         go= gdoc->fGoview->SelectedGopher();
  581.                         if (go && go->fAdminEmail) {
  582.                             win= new DAdminMailDialog(0, this, go);
  583.                             win->Open();
  584.                             }
  585.                         break;
  586. #endif
  587.                     }
  588.                 }
  589.             return true;
  590.             }
  591. #endif
  592.  
  593.          case    kMailSetup:
  594.             {
  595.             win= new DMailSetupDialog(0, this, -10, -10, -20, -20, "Mail Setup");
  596.             win->Open();
  597.             return true;
  598.             }
  599.         case     kSendMail: 
  600.             {
  601.             win= new DSendMailDialog(0, this, -10, -10, -20, -20, "Send Mail");
  602.             win->Open();
  603.             return true;
  604.             }
  605.         case  kBugMail:
  606.             {
  607.             win= new DBugMailDialog(0, this, -10, -10, -20, -20, "Comment about this App");
  608.             win->Open();
  609.             return true;
  610.             }
  611.             
  612.         default:    
  613.             if (sdoc && sdoc->Id() == DSeqDoc::kSeqdoc) 
  614.                 return sdoc->IsMyAction(action);
  615.             else return false;
  616.         }
  617. }
  618.  
  619.  
  620. Boolean DSeqPup::DoMenuTask(long tasknum, DTask* theTask)
  621. {
  622.     switch (tasknum) {
  623.     
  624.         case kPrintAFile:    
  625.         case kOpenAFile:
  626.             DSeqDoc::fgTestSeqFile= true;  
  627.             (void) DApplication::DoMenuTask(tasknum,theTask);
  628.             DSeqDoc::fgTestSeqFile= false;
  629.             return true;
  630.             
  631.         default: 
  632.             return DApplication::DoMenuTask(tasknum, theTask);
  633.         }
  634. }
  635.  
  636.  
  637. Boolean DSeqPup::IsMyAction(DTaskMaster* action) 
  638. {
  639.     enum doctype { nodoc, anydoc, godoc, seq1doc, alndoc };
  640.     static DTaskMaster* curaction = NULL;
  641.     doctype        thedoc = nodoc;
  642.     Boolean        done= true, result= false;
  643.     
  644.     Boolean inrecurse= (curaction == action);  
  645.     if (inrecurse) return false; // prevent infinite loop here...
  646.     curaction= action;
  647.     
  648.     DWindow* win     = gWindowManager->CurrentWindow();
  649.     DSeqDoc* sdoc = (DSeqDoc*) win;
  650.     DSeqedWindow* s1doc= (DSeqedWindow*) win;
  651. #if UseGopher
  652.     DGopherListDoc* gdoc = (DGopherListDoc*) win;
  653. #endif
  654.     if (win) {
  655.         if (win->Id() == DSeqDoc::kSeqdoc) thedoc = alndoc;
  656.         else if (win->Id() == DSeqedWindow::kId) thedoc = seq1doc;
  657. #if UseGopher
  658.         else if (win->Id() == DGopherListDoc::kGoListdoc) thedoc = godoc;
  659. #endif
  660.         else thedoc= anydoc;
  661.         }
  662.         
  663.     short    menuitem = action->Id();
  664.     short menuid= (action->fSuperior) ? action->fSuperior->Id() : 0;
  665.  
  666.     if ((menuid == kInternetMenu
  667.         ||menuid == DSeqApps::kChildMenu)
  668.      && (menuitem >= DSeqApps::kChildMenuBaseID 
  669.          && menuitem <= DSeqApps::kChildMenuBaseID + 50) // +50 = HACK !! need better way to distinguish menu items !
  670.     ) goto caseChildMenu;
  671.         
  672.     if (action->fSuperior)  
  673.         switch (action->fSuperior->Id()) {
  674.                 
  675.             case kOpenMenu : 
  676.             case cFileMenu : 
  677.               switch (menuitem) {
  678.               
  679.                 case kNewServer:
  680.                     result= IsInternetMenu(action);
  681.                     break;
  682.                     
  683.                 case DSeqDoc::cSaveSel:
  684.                 case DSeqDoc::cRevert:
  685.                     goto caseSeqDoc;
  686.                     
  687.                 case DApplication::kNew:
  688. #if DEBUG
  689.                     if ( gKeys->option()) { 
  690.                         DebugNewReportLeaks();
  691.                         }
  692.                     else
  693. #endif
  694.                         DSeqDoc::NewSeqDoc();
  695.                     result= true;
  696.                     break;
  697.                     
  698.                 case kOpenText:
  699.                     DApplication::DoMenuTask(DApplication::kOpen, NULL);
  700.                     result= true;
  701.                     break;
  702.                     
  703.                 case kOpenTree:
  704.                     result= true;
  705.                     break;
  706.  
  707.                 case kOpenAppendSeq:
  708.                     fAppendSeq= true;
  709.                 case kOpenSeq:
  710.                 case DApplication::kOpen:
  711.                     DSeqDoc::fgTestSeqFile= true; // ???
  712.                     DApplication::DoMenuTask(DApplication::kOpen,NULL);
  713.                     DSeqDoc::fgTestSeqFile= false;
  714.                     fAppendSeq= false;
  715.                     result= true;
  716.                     break;
  717.                     
  718. #if UseGopher
  719.                 case kOpenLocalGo:
  720.                     OpenLocalGopher();
  721.                     result= true;
  722.                     break;
  723. #endif
  724.                  default: 
  725.                     result= DApplication::IsMyAction(action);
  726.                     break;
  727.                 }
  728.                 break;
  729.         
  730.             case DApplication::cEditMenu:
  731.                 if (thedoc == alndoc) done= sdoc->IsMyAction(action);
  732.                 else if (thedoc == seq1doc) done= s1doc->IsMyAction(action);
  733.                 else done= false;
  734.                 if (done) result= true;
  735.                 break;
  736.                 
  737.             case kInternetMenu    :
  738.             case kPrefsMenu : 
  739. #if UseGopher
  740.                 if (menuitem == DGopherListDoc::kViewChoiceMenu) 
  741.                     goto caseViewChoiceMenu; 
  742.                 else
  743. #endif
  744.                   result= IsInternetMenu(action);
  745.                 break;
  746.                     
  747. #if UseGopher
  748.             case DGopherListDoc::kViewKindMenu    : 
  749.                 if (thedoc == godoc) result= gdoc->IsMyAction(action);
  750.                 else result= false;
  751.                 beak;
  752.                 
  753.             case DGopherListDoc::kViewChoiceMenu    : 
  754.             caseViewChoiceMenu:
  755.                 if (thedoc == godoc) result= gdoc->IsMyAction(action);
  756.                 else result= false;
  757.                 break;
  758. #endif
  759.             
  760.             case DSeqApps::kChildMenu :
  761.             caseChildMenu:
  762.                 if (thedoc == alndoc) result= sdoc->IsMyAction(action);
  763.                 else if (thedoc == seq1doc) result= s1doc->IsMyAction(action);
  764.                 else {
  765.                     DSeqApps::CallChildApp( menuitem, NULL);
  766.                     result= true;
  767.                     }
  768.                 break;
  769.  
  770.             case DSeqDoc::kSeqMenu    : 
  771.             case DSeqDoc::kViewKindMenu    : 
  772.             case DSeqDoc::kSeqMaskMenu    : 
  773.             caseSeqDoc:
  774.                 switch(menuitem) {
  775.                     case DSeqDoc::cNAcodes: NucCodesPicture(); result= true; break;
  776.                     case DSeqDoc::cAAcodes: AminoCodesPicture(); result= true; break;
  777.                     default:
  778.                         if (thedoc == alndoc) result= sdoc->IsMyAction(action);
  779.                         else if (thedoc == seq1doc) result= s1doc->IsMyAction(action);
  780.                         else result= false;
  781.                         break;
  782.                     }
  783.                 break;
  784.                 
  785.             default:
  786.                 done= false;
  787.                 break;
  788.             }
  789.      
  790.      
  791.     if (!done) switch(menuitem) {
  792.         case DApplication::kNew:
  793.             DSeqDoc::NewSeqDoc();
  794.             result= true;
  795.             break;
  796.         default: 
  797.             result= DApplication::IsMyAction(action);
  798.             break;
  799.         }
  800.          
  801.     inrecurse= false;
  802.     curaction= NULL;
  803.     return result;
  804. }
  805.  
  806.  
  807.  
  808. void DSeqPup::UpdateMenus(void)
  809. {
  810.     DApplication::UpdateMenus();
  811.     
  812.     //gViewCentral->EnableView(kSpecial1);
  813.     //gViewCentral->EnableView(kSpecial2);
  814. }
  815.  
  816.  
  817.